import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
import 'package:first/randow/RandomWords.dart';

class StydyAll extends StatefulWidget {
//  @override
//  createState() => new StudyAllState();
    @override
    createState() => new StudyAllState();
}

class StudyAllState extends State<StydyAll> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new AxConstrainedBox();
  }
}

/*
  Align 对齐方式
 */
class AxAlign extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Align(
      //距离锚点距离
      alignment: Alignment(-0.5, 1.0),
      //子视图width的倍数 不设置为充满
      widthFactor: 3.0,
      //子视图height的倍数 不设置为充满
      heightFactor: 2.0,
      child: Container(
        color: Colors.green,
        width: 100,
        height: 50,
        child: Text(
          'align',
          style: TextStyle(color: Colors.white),
        ),
      ),
    );
  }
}

/*
  AppBar 头部栏
 */

class AxAppBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return moreButton();
    return new AppBar(
      title: Text('应用'),
      centerTitle: true,
      actions: <Widget>[
        IconButton(
            icon: Icon(Icons.book),
            tooltip: 'book',
            onPressed: () {
              return _pushView(Text('book'));
            }),
        IconButton(
            icon: Icon(Icons.more),
            tooltip: 'more',
            onPressed: () {
              return _pushView(Text('more'));
            }),
        IconButton(
            icon: Icon(Icons.share),
            tooltip: 'share',
            onPressed: () {
              return _pushView(Text('share'));
            }),
      ],
    );
  }

  Widget moreButton() {
    return SizedBox(
      height: 500,
      child: AppBar(
        title: Text('标题'),
        leading: Icon(Icons.home),
        backgroundColor: Colors.green,
        centerTitle: true,
        actions: <Widget>[
          IconButton(
              icon: Icon(Icons.share),
              tooltip: 'share',
              onPressed: () {
                return _pushView(Text('share'));
              }),
          PopupMenuButton<String>(
            itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
              PopupMenuItem<String>(
                value: 'friend',
                child: Text('分享到朋友圈'),
              ),
              PopupMenuItem<String>(
                value: 'download',
                child: Text('下载'),
              )
            ],
          )
        ],
      ),
    );
  }

  void _pushView(Text text) {}
}

/*
   BottomAppBar
 */
class AxBottomAppBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: 'BottomAppBar',
      home: Scaffold(
        //FAB按钮位置
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        //FAB按钮
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () {},
        ),
        //底部应用栏
        bottomNavigationBar: BottomAppBar(
          //floatingActionButton BottomAppBar 之间的距离
          notchMargin: 10.0,
          color: Colors.green,
          child: Row(
            //设置大小
            mainAxisSize: MainAxisSize.max,
            //对齐方式
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              IconButton(icon: Icon(Icons.menu), onPressed: () {}),
              IconButton(icon: Icon(Icons.search), onPressed: () {}),
            ],
          ),
        ),
      ),
    );
  }
}

/*
  ButtonBar 末端按钮对齐的容器
  应用 有几个按钮排列一致时可使用
 */
class AxButtonBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: ButtonBar(
        //容器内按钮对齐方式
        alignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          RaisedButton(
            onPressed: () {},
            child: Text('button1'),
            color: Colors.yellowAccent,
          ),
          RaisedButton(
            onPressed: () {},
            child: Text('button2'),
            color: Colors.yellowAccent,
          ),
          RaisedButton(
            onPressed: () {},
            child: Text('button3button3button3'),
            color: Colors.yellowAccent,
          ),
          RaisedButton(
            onPressed: () {},
            child: Text('button3'),
            color: Colors.yellowAccent,
          ),
          RaisedButton(
            onPressed: () {},
            child: Text('button3'),
            color: Colors.yellowAccent,
          ),
        ],
      ),
    );
  }
}

/*
   FlexibelSpaceBar 可折叠组件
 */
class AxFlexibelSpaceBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return NestedScrollView(
      //
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
            //展开高度
            expandedHeight: 250.0,
            //是否随着滑动隐藏标题
            floating: false,
            //是否固定在顶部
            pinned: true,
            flexibleSpace: FlexibleSpaceBar(
              centerTitle: true,
              title: Text(
                '可折叠的组件',
                style: TextStyle(color: Colors.black, fontSize: 16.0),
              ),
              background: Image.network(
                'https://pics1.baidu.com/feed/14ce36d3d539b60058d6b42ae19b562cc75cb760.jpeg?token=0c649c8f0447d4aed0da5ab116726778',
                fit: BoxFit.contain,
              ),
            ),
          ),
        ];
      },
      body: Center(
        child: new RandomWords(),
      ),
    );
  }
}

/*
   AxSliverAppBar 滑动展示和隐藏的appbar
   应用可以搭配list使用
 */
class AxSliverAppBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final WordPair wordPair = new WordPair.random();
    return NestedScrollView(
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
//            按钮主题
//            actionsIconTheme: ,
            //是否预留高度
            primary: true,
            //标题前面显示的一个空间
            leading: Icon(Icons.home),
            actions: <Widget>[
              Icon(Icons.add),
              Icon(Icons.add),
            ],
            //是否固定在顶部
            pinned: true,
            //可扩展区域
            expandedHeight: 200.0,
            //与floating结合使用
            snap: false,
            //是否随着滑动隐藏标题
            floating: true,
            flexibleSpace: FlexibleSpaceBar(
              centerTitle: true,
              title: Text(
                '标题',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 16.0,
                ),
              ),
              background: Image.network(
                'https://pics1.baidu.com/feed/14ce36d3d539b60058d6b42ae19b562cc75cb760.jpeg?token=0c649c8f0447d4aed0da5ab116726778',
                fit: BoxFit.contain,
              ),
            ),
          ),
          new SliverFixedExtentList(
            itemExtent: 50.0,
            delegate:
                new SliverChildBuilderDelegate((context, index) => new ListTile(
                      title: new Text(wordPair.asPascalCase),
                    )),
          ),
        ];
      },
      body: Text(''),
    );
  }
}

/*
    AxBottomNavigationBar 底部按钮
 */
class AxBottomNavigationBar extends StatefulWidget {
  @override
  createState() =>new AxBottomNavigationBarState();
}
class AxBottomNavigationBarState extends State<AxBottomNavigationBar> {

  int _currentIndex = 1;

  void _onItemTaped(int index){
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return BottomNavigationBar(
      type: BottomNavigationBarType.fixed,
      iconSize: 25,
      onTap: _onItemTaped,
      currentIndex: _currentIndex,
      fixedColor: Colors.red,
      items: <BottomNavigationBarItem>[
        BottomNavigationBarItem(icon: Icon(Icons.chat),title: Text('聊天')),
        BottomNavigationBarItem(icon: Icon(Icons.add),title: Text('朋友圈')),
        BottomNavigationBarItem(icon: Icon(Icons.person),title: Text('我的')),
      ],
    );
  }
}

/*
    AxConstrainedBox  限定宽高盒子
 */

class AxConstrainedBox extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: Column(
        children: <Widget>[
          ConstrainedBox(constraints: const BoxConstraints(
            minHeight: 20,minWidth: 100,
            maxHeight: 60, maxWidth: 200,
          ),
          child: Container(
            width: 150,
            height: 80,
            child: Text('text',style: TextStyle(color: Colors.red),),
            color: Colors.green,
          ),
          )
        ],
      ),
    );
  }

}
